home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / vgl20.zip / VGL286.ASM < prev    next >
Assembly Source File  |  1993-05-16  |  20KB  |  651 lines

  1. ; ****************************************************************************
  2. ; VGL286.ASM
  3. ;
  4. ; This module is exactly the same as VGL386.ASM except that it should work on
  5. ; 286's and up.  Theoretically the 386 version should be faster, as it uses
  6. ; 32 bit reads and writes wherever possible.  In my simple tests the 386
  7. ; version is quite a bit faster than the 286 version, but it seems to vary a
  8. ; bit depending on your setup.
  9. ;
  10. ; I couldn't find a 286 anywhere close to test this on.  I simply took a copy
  11. ; of VGL386.ASM and changed all the 386'ish parts.  It still works on my 486,
  12. ; so I'm assuming it'll work on a 286 as well.  Please let me know if you
  13. ; discover otherwise.
  14. ;
  15. ; Mark
  16. ; morley@camosun.bc.ca
  17. ; ****************************************************************************
  18.  
  19. LOCALS
  20. .model small
  21. .286
  22.  
  23. ; ****************************************************************************
  24. ; EQUates
  25. ; ****************************************************************************
  26.  
  27. VIDEO       equ         0a000h                  ; Start of video memory
  28.  
  29. ; ****************************************************************************
  30. ; Data Section
  31. ; ****************************************************************************
  32.  
  33. .data
  34.  
  35. ; Where we're going to draw into (defaults to video memory)
  36. _Buffer                 dw  VIDEO
  37.  
  38. ; Table for quick Y calculations
  39. RowOff                  dw      0,  320,  640,  960, 1280, 1600, 1920, 2240
  40.                         dw   2560, 2880, 3200, 3520, 3840, 4160, 4480, 4800
  41.                         dw   5120, 5440, 5760, 6080, 6400, 6720, 7040, 7360
  42.                         dw   7680, 8000, 8320, 8640, 8960, 9280, 9600, 9920
  43.                         dw  10240,10560,10880,11200,11520,11840,12160,12480
  44.                         dw  12800,13120,13440,13760,14080,14400,14720,15040
  45.                         dw  15360,15680,16000,16320,16640,16960,17280,17600
  46.                         dw  17920,18240,18560,18880,19200,19520,19840,20160
  47.                         dw  20480,20800,21120,21440,21760,22080,22400,22720
  48.                         dw  23040,23360,23680,24000,24320,24640,24960,25280
  49.                         dw  25600,25920,26240,26560,26880,27200,27520,27840
  50.                         dw  28160,28480,28800,29120,29440,29760,30080,30400
  51.                         dw  30720,31040,31360,31680,32000,32320,32640,32960
  52.                         dw  33280,33600,33920,34240,34560,34880,35200,35520
  53.                         dw  35840,36160,36480,36800,37120,37440,37760,38080
  54.                         dw  38400,38720,39040,39360,39680,40000,40320,40640
  55.                         dw  40960,41280,41600,41920,42240,42560,42880,43200
  56.                         dw  43520,43840,44160,44480,44800,45120,45440,45760
  57.                         dw  46080,46400,46720,47040,47360,47680,48000,48320
  58.                         dw  48640,48960,49280,49600,49920,50240,50560,50880
  59.                         dw  51200,51520,51840,52160,52480,52800,53120,53440
  60.                         dw  53760,54080,54400,54720,55040,55360,55680,56000
  61.                         dw  56320,56640,56960,57280,57600,57920,58240,58560
  62.                         dw  58880,59200,59520,59840,60160,60480,60800,61120
  63.                         dw  61440,61760,62080,62400,62720,63040,63360,63680
  64.  
  65. ; ****************************************************************************
  66. ; Macros
  67. ; ****************************************************************************
  68.  
  69.                  VSYNC macro
  70.  
  71.                  mov  dx,03DAh
  72. @@1:
  73.                  in   al,dx
  74.                  test al,8
  75.                  jnz  @@1
  76. @@2:
  77.                  in   al,dx
  78.                  test al,8
  79.                  jz   @@2
  80.  
  81.                  endm
  82.  
  83. ; ****************************************************************************
  84. ; Code Section
  85. ; ****************************************************************************
  86.  
  87. .code
  88.  
  89. ; ============================================================================
  90. ; void vglInit( void )
  91. ;
  92. ; Enter mode 13h.
  93. ; ============================================================================
  94.  
  95.                  public _vglInit
  96.  
  97. _vglInit         proc near
  98.  
  99.                  mov  ax,13h
  100.                  int  10h
  101.                  mov  _Buffer,VIDEO
  102.  
  103.                  ret
  104. _vglInit         endp
  105.  
  106. ; ============================================================================
  107. ; void vglTerm( void )
  108. ;
  109. ; Exit mode 13h.
  110. ; ============================================================================
  111.  
  112.                  public _vglTerm
  113.  
  114. _vglTerm         proc near
  115.  
  116.                  mov  ax,3
  117.                  int  10h
  118.  
  119.                  ret
  120. _vglTerm         endp
  121.  
  122. ; ============================================================================
  123. ; void vglBuffer( char far* buffer )
  124. ;
  125. ; Point the routines at a different area of memory ("virtual" screens)
  126. ; ============================================================================
  127.  
  128.                  public _vglBuffer
  129.  
  130. _vglBuffer       proc near
  131.                  push bp
  132.                  mov  bp,sp
  133.  
  134.                  les  ax,[bp+4]
  135.                  mov  _Buffer,es
  136.  
  137.                  pop  bp
  138.                  ret
  139. _vglBuffer       endp
  140.  
  141. ; ============================================================================
  142. ; void vglClear( int c )
  143. ;
  144. ; Clear the current "screen" to a given color.
  145. ; ============================================================================
  146.  
  147.                  public _vglClear
  148.  
  149. _vglClear        proc near
  150.                  push bp
  151.                  mov  bp,sp
  152.  
  153.                  mov  es,_Buffer
  154.                  xor  di,di
  155.                  mov  dl,[bp+4]
  156.                  mov  al,dl
  157.                  mov  ah,dl
  158.                  mov  cx,32000
  159.                  rep  stosw
  160.  
  161.                  pop  bp
  162.                  ret
  163. _vglClear        endp
  164.  
  165. ; ============================================================================
  166. ; void vglClearL( int lines, int c )
  167. ;
  168. ; Clear the top 'lines' rows of the current screen to the specified color.
  169. ; ============================================================================
  170.  
  171.                  public _vglClearL
  172.  
  173. _vglClearL       proc near
  174.                  push bp
  175.                  mov  bp,sp
  176.  
  177.                  mov  es,_Buffer
  178.                  xor  di,di
  179.                  mov  ax,160
  180.                  mov  bx,[bp+4]
  181.                  mul  bx
  182.                  mov  cx,ax
  183.                  mov  dl,[bp+6]
  184.                  mov  al,dl
  185.                  mov  ah,dl
  186.                  rep  stosw
  187.  
  188.                  pop  bp
  189.                  ret
  190. _vglClearL       endp
  191.  
  192. ; ============================================================================
  193. ; void vglUpdate( void )
  194. ;
  195. ; Copy the current "screen" into video memory.  Useless if you're not currently
  196. ; drawing into an off-screen buffer.
  197. ; ============================================================================
  198.  
  199.                  public _vglUpdate
  200.  
  201. _vglUpdate       proc near
  202.                  push bp
  203.                  mov  bp,sp
  204.                  push ds
  205.  
  206.                  mov  ds,_Buffer
  207.                  xor  si,si
  208.                  mov  ax,VIDEO
  209.                  mov  es,ax
  210.                  xor  di,di
  211.                  mov  cx,32000
  212.                  rep  movsw
  213.  
  214.                  pop  ds
  215.                  pop  bp
  216.                  ret
  217. _vglUpdate       endp
  218.  
  219. ; ============================================================================
  220. ; void vglUpdateW( void )
  221. ;
  222. ; Same as above but it waits for vertical retrace.
  223. ; ============================================================================
  224.  
  225.                  public _vglUpdateW
  226.  
  227. _vglUpdateW      proc near
  228.                  push bp
  229.                  mov  bp,sp
  230.                  push ds
  231.  
  232.                  VSYNC
  233.  
  234.                  mov  ds,_Buffer
  235.                  xor  si,si
  236.                  mov  ax,VIDEO
  237.                  mov  es,ax
  238.                  xor  di,di
  239.                  mov  cx,32000
  240.                  rep  movsw
  241.  
  242.                  pop  ds
  243.                  pop  bp
  244.                  ret
  245. _vglUpdateW      endp
  246.  
  247. ; ============================================================================
  248. ; void vglUpdateL( int lines )
  249. ;
  250. ; Same as vglUpdate() except it only copies over the top 'lines' rows.
  251. ; ============================================================================
  252.  
  253.                  public _vglUpdateL
  254.  
  255. _vglUpdateL      proc near
  256.                  push bp
  257.                  mov  bp,sp
  258.                  push ds
  259.  
  260.                  mov  ds,_Buffer
  261.                  xor  si,si
  262.                  mov  ax,VIDEO
  263.                  mov  es,ax
  264.                  xor  di,di
  265.                  mov  ax,160
  266.                  mov  bx,[bp+4]
  267.                  mul  bx
  268.                  mov  cx,ax
  269.                  rep  movsw
  270.  
  271.                  pop  ds
  272.                  pop  bp
  273.                  ret
  274. _vglUpdateL      endp
  275.  
  276. ; ============================================================================
  277. ; void vglUpdateLW( int lines )
  278. ;
  279. ; Same as above but it waits for vertical retrace.
  280. ; ============================================================================
  281.  
  282.                  public _vglUpdateLW
  283.  
  284. _vglUpdateLW     proc near
  285.                  push bp
  286.                  mov  bp,sp
  287.                  push ds
  288.  
  289.                  VSYNC
  290.  
  291.                  mov  ds,_Buffer
  292.                  xor  si,si
  293.                  mov  ax,VIDEO
  294.                  mov  es,ax
  295.                  xor  di,di
  296.                  mov  ax,160
  297.                  mov  bx,[bp+4]
  298.                  mul  bx
  299.                  mov  cx,ax
  300.                  rep  movsw
  301.  
  302.                  pop  ds
  303.                  pop  bp
  304.                  ret
  305. _vglUpdateLW     endp
  306.  
  307. ; ============================================================================
  308. ; void vglBox( int left, int top, int width, int height, int c )
  309. ;
  310. ; Draw a filled in box at offset x,y that is width x height big, in the
  311. ; specified color.  It is draw into the current "screen" (buffer).
  312. ; ============================================================================
  313.  
  314.                  public _vglBox
  315.  
  316. _vglBox          proc near
  317.                  push bp
  318.                  mov  bp,sp
  319.  
  320.                  mov  es,_Buffer
  321.                  mov  bx,[bp+6]
  322.                  shl  bx,1
  323.                  mov  di,[RowOff+bx]
  324.                  add  di,[bp+4]
  325.                  mov  cl,[bp+12]
  326.                  mov  al,cl
  327.                  mov  ah,cl
  328.                  mov  dx,[bp+10]
  329.                  mov  bp,[bp+8]
  330.                  mov  bx,320
  331.                  sub  bx,bp
  332.                  mov  si,bp
  333.                  and  si,1
  334.                  shr  bp,1
  335. BLoop:
  336.                  mov  cx,bp
  337.                  rep  stosw
  338.                  mov  cx,si
  339.                  rep  stosb
  340.                  add  di,bx
  341.                  dec  dx
  342.                  jnz  BLoop
  343.  
  344.                  pop  bp
  345.                  ret
  346. _vglBox          endp
  347.  
  348. ; ============================================================================
  349. ; void vglHLine( int line, int left, int width, int c )
  350. ;
  351. ; Draw a horizontal line in a specified color.
  352. ; ============================================================================
  353.  
  354.                  public _vglHLine
  355.  
  356. _vglHLine        proc near
  357.                  push bp
  358.                  mov  bp,sp
  359.  
  360.                  mov  es,_Buffer
  361.                  mov  bx,[bp+4]
  362.                  shl  bx,1
  363.                  mov  di,[RowOff+bx]
  364.                  add  di,[bp+6]
  365.                  mov  cl,[bp+10]
  366.                  mov  al,cl
  367.                  mov  ah,cl
  368.                  mov  cx,[bp+8]
  369.                  mov  si,cx
  370.                  and  si,1
  371.                  shr  cx,1
  372.                  rep  stosw
  373.                  mov  cx,si
  374.                  rep  stosb
  375.  
  376.                  pop  bp
  377.                  ret
  378. _vglHLine        endp
  379.  
  380. ; ============================================================================
  381. ; void vglCopy( int left, int top, int width, int height )
  382. ;
  383. ; Like vglUpdate() except it updates only a region of the screen.
  384. ; ============================================================================
  385.  
  386.                  public _vglCopy
  387.  
  388. _vglCopy         proc near
  389.                  push bp
  390.                  mov  bp,sp
  391.                  push ds
  392.  
  393.                  mov  bx,[bp+6]
  394.                  shl  bx,1
  395.                  mov  di,[RowOff+bx]
  396.                  add  di,[bp+4]
  397.                  mov  ds,_Buffer
  398.                  mov  ax,VIDEO
  399.                  mov  es,ax
  400.                  mov  dx,[bp+10]
  401.                  mov  bx,[bp+8]
  402.                  mov  bp,320
  403.                  sub  bp,bx
  404.                  mov  ax,bx
  405.                  and  ax,1
  406.                  shr  bx,1
  407. CLoop:
  408.                  mov  si,di
  409.                  mov  cx,bx
  410.                  rep  movsw
  411.                  mov  cx,ax
  412.                  rep  movsb
  413.                  add  di,bp
  414.                  dec  dx
  415.                  jnz  CLoop
  416.  
  417.                  pop  ds
  418.                  pop  bp
  419.                  ret
  420. _vglCopy         endp
  421.  
  422. ; ============================================================================
  423. ; void vglCopyW( int left, int top, int width, int height )
  424. ;
  425. ; Same as above but waits for vertical retrace.
  426. ; ============================================================================
  427.  
  428.                  public _vglCopyW
  429.  
  430. _vglCopyW        proc near
  431.                  push bp
  432.                  mov  bp,sp
  433.                  push ds
  434.  
  435.                  VSYNC
  436.  
  437.                  mov  bx,[bp+6]
  438.                  shl  bx,1
  439.                  mov  di,[RowOff+bx]
  440.                  add  di,[bp+4]
  441.                  mov  ds,_Buffer
  442.                  mov  ax,VIDEO
  443.                  mov  es,ax
  444.                  mov  dx,[bp+10]
  445.                  mov  bx,[bp+8]
  446.                  mov  bp,320
  447.                  sub  bp,bx
  448.                  mov  ax,bx
  449.                  and  ax,1
  450.                  shr  bx,1
  451. CWLoop:
  452.                  mov  si,di
  453.                  mov  cx,bx
  454.                  rep  movsw
  455.                  mov  cx,ax
  456.                  rep  movsb
  457.                  add  di,bp
  458.                  dec  dx
  459.                  jnz  CWLoop
  460. CWEnd:
  461.                  pop  ds
  462.                  pop  bp
  463.                  ret
  464. _vglCopyW        endp
  465.  
  466. ; ============================================================================
  467. ; void vglPutPel( int x, int y, int c )
  468. ;
  469. ; Draw a single pixel in the specified color at offset x,y.  Pixel is drawn
  470. ; into the current "screen".
  471. ; ============================================================================
  472.  
  473.                  public _vglPutPel
  474.  
  475. _vglPutPel       proc near
  476.                  push bp
  477.                  mov  bp,sp
  478.  
  479.                  mov  es,_Buffer
  480.                  mov  bx,[bp+6]
  481.                  shl  bx,1
  482.                  mov  di,[RowOff+bx]
  483.                  add  di,[bp+4]
  484.                  mov  al,[bp+8]
  485.                  mov  [es:di],al
  486.  
  487.                  pop  bp
  488.                  ret
  489. _vglPutPel       endp
  490.  
  491. ; ============================================================================
  492. ; int vglGetPel( int x, int y )
  493. ;
  494. ; Get the color of the pixel at location x,y in the current "screen".
  495. ; ============================================================================
  496.  
  497.                  public _vglGetPel
  498.  
  499. _vglGetPel       proc near
  500.                  push bp
  501.                  mov  bp,sp
  502.  
  503.                  mov  es,_Buffer
  504.                  mov  bx,[bp+6]
  505.                  shl  bx,1
  506.                  mov  di,[RowOff+bx]
  507.                  add  di,[bp+4]
  508.                  mov  al,[bp+8]
  509.                  mov  al,[es:di]
  510.  
  511.                  pop  bp
  512.                  ret
  513. _vglGetPel       endp
  514.  
  515. ; ============================================================================
  516. ; void vglPut( int x, int y, int w, int h, char far* buf )
  517. ;
  518. ; Draw a bitmap image into the buffer at location x,y.  Every pixel of the
  519. ; image is drawn, so no transparent areas are possible.  Very quick.  Good
  520. ; for drawing tiles in a tile based game!
  521. ; ============================================================================
  522.  
  523.                  public _vglPut
  524.  
  525. _vglPut          proc near
  526.                  push bp
  527.                  mov  bp,sp
  528.                  push ds
  529.  
  530.                  mov  es,_Buffer
  531.                  mov  bx,[bp+6]
  532.                  shl  bx,1
  533.                  mov  di,[RowOff+bx]
  534.                  add  di,[bp+4]
  535.                  lds  si,[bp+12]
  536.                  mov  bx,[bp+8]
  537.                  mov  dx,[bp+10]
  538.                  mov  bp,320
  539.                  sub  bp,bx
  540.                  mov  ax,bx
  541.                  and  ax,1
  542.                  shr  bx,1
  543. PLoop:
  544.                  mov  cx,bx
  545.                  rep  movsw
  546.                  mov  cx,ax
  547.                  rep  movsb
  548.                  add  di,bp
  549.                  dec  dx
  550.                  jnz  PLoop
  551.  
  552.                  pop  ds
  553.                  pop  bp
  554.                  ret
  555. _vglPut          endp
  556.  
  557. ; ============================================================================
  558. ; void vglPutSprite( int x, int y, int w, int h, char far* buf )
  559. ;
  560. ; Like vglPut() except that any pixels of color 0 will be transparent.  Not
  561. ; nearly as fast as vglPut(), but what can you do?
  562. ; ============================================================================
  563.  
  564.                  public _vglPutSprite
  565.  
  566. _vglPutSprite    proc near
  567.                  push bp
  568.                  mov  bp,sp
  569.                  push ds
  570.  
  571.                  mov  es,_Buffer
  572.                  mov  bx,[bp+6]
  573.                  shl  bx,1
  574.                  mov  di,[RowOff+bx]
  575.                  add  di,[bp+4]
  576.                  lds  si,[bp+12]
  577.                  mov  bx,[bp+8]
  578.                  mov  dx,[bp+10]
  579.                  mov  bp,320
  580.                  sub  bp,bx
  581. PSLoop1:
  582.                  mov  cx,bx
  583. PSLoop2:
  584.                  lodsb
  585.                  or   al,al
  586.                  je   PSSkip
  587.                  mov  [es:di],al
  588. PSSkip:
  589.                  inc  di
  590.                  dec  cx
  591.                  jne  PSLoop2
  592.                  add  di,bp
  593.                  dec  dx
  594.                  jnz  PSLoop1
  595.  
  596.                  pop  ds
  597.                  pop  bp
  598.                  ret
  599. _vglPutSprite    endp
  600.  
  601. ; ============================================================================
  602. ; void vglSetPal( char pal[768] )
  603. ;
  604. ; Set the palette from an array of 256 RGB triples.
  605. ; ============================================================================
  606.  
  607.                  public _vglSetPal
  608.  
  609. _vglSetPal       proc near
  610.                  push bp
  611.                  mov  bp,sp
  612.  
  613.                  VSYNC
  614.  
  615.                  mov  ax,1012h
  616.                  xor  bx,bx
  617.                  mov  cx,256
  618.                  les  dx,[bp+4]
  619.                  int  10h
  620.  
  621.                  pop  bp
  622.                  ret
  623. _vglSetPal       endp
  624.  
  625. ; ============================================================================
  626. ; void vglSetPartPal( int first, int num, char far* pal )
  627. ;
  628. ; Set a partial palette from an array of RGB triples.
  629. ; ============================================================================
  630.  
  631.                  public _vglSetPartPal
  632.  
  633. _vglSetPartPal   proc near
  634.                  push bp
  635.                  mov  bp,sp
  636.  
  637.                  VSYNC
  638.  
  639.                  mov  ax,1012h
  640.                  mov  bx,[bp+4]
  641.                  mov  cx,[bp+6]
  642.                  les  dx,[bp+8]
  643.                  int  10h
  644.  
  645.                  pop  bp
  646.                  ret
  647. _vglSetPartPal   endp
  648.  
  649. end
  650.  
  651.